using System;
using System.Collections.Generic;
using System.Text;
using Musicman.Entities.BusinessEntities;

namespace Musicman.Entities
{
	public class Searchlocation
	{
		private int? searchlocationid;
		private long? searchjobid;
		private string name;
        private SearchFolderCollection folders;

        public Searchlocation()
        {
            this.folders = new SearchFolderCollection();
        }

        public void AddSearchfolder(Searchfolder folder)
        {
            folder.SearchLocation = this;
            folders.Add(folder);
        }

        public void RemoveSearchFolder(Searchfolder folder)
        {
            this.folders.Remove(folder);
        }

        public void AddSearchFile(Searchfile file)
        {
            Searchfolder sFolderOld;
            Searchfolder sf = file.Folder;
            if (this.folders.Contains(sf))
            {
                sFolderOld = this.folders[sf.Name];
                sFolderOld.CopyProperties(sf);
            }
            else
            {
                sFolderOld = new Searchfolder(this);
                sFolderOld.Searchlocationid = this.searchlocationid;
                sFolderOld.CopyProperties(sf);
                this.folders.Add(sFolderOld);
            }
            sFolderOld.AddSearchFile(file);
        }

        public void CopyProperties(Searchlocation location)
        {
            this.name = location.name;
        }

        public int? Searchlocationid
		{
			get { return searchlocationid; }
			set 
            { 
                this.searchlocationid = value;
                for (int i = 0; i < this.folders.Count; i++)
                {
                    this.folders[i].Searchlocationid = value;
                }
            }
		}
            public long? Searchjobid
		{
			get { return searchjobid; }
			set { this.searchjobid = value; }
		}
		public string Name
		{
			get { return name; }
			set { this.name = value; }
		}
        public List<Searchfolder> Folders
        {
            get { return folders.InnerList; }
        }
	}
}
